#include "temporaryfile.h"
#include "stdafx.h"
namespace Moonlite {
namespace Data {
namespace Mpq {
	System::String^ TTemporaryFile::FileName::get()
	{
		if (_disposed)
		{
			throw gcnew System::ObjectDisposedException(nullptr);
		}

		return _filename;
	}

	void TTemporaryFile::CopyTo(array<System::Byte>^ data, int index)
	{
		if (_disposed)
		{
			throw gcnew System::ObjectDisposedException(nullptr);
		}

		System::IO::File::ReadAllBytes(_filename)->CopyTo(data, index);
	}

	void TTemporaryFile::Cleanup(bool managed)
	{
		UNREFERENCED_PARAMETER(managed);
		System::IO::File::Delete(_filename);
		_filename = "";
	}

	TTemporaryFile::TTemporaryFile()
	{
		_filename = System::IO::Path::GetTempFileName();
	}

	TTemporaryFile::TTemporaryFile(array<System::Byte>^ data)
	{
		_filename = System::IO::Path::GetTempFileName();
		System::IO::File::WriteAllBytes(_filename, data);
	}

	TTemporaryFile::~TTemporaryFile()
	{
		Cleanup(true);
		_disposed = true;
	}

	TTemporaryFile::!TTemporaryFile()
	{
		Cleanup(false);
		_disposed = false;
	}
}
}
}